﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;

namespace vietnameseprocessing
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Console.WriteLine("################################################################################");
            Console.WriteLine("------------------------------Debug Console Panel-------------------------------");
            Console.WriteLine("################################################################################");
            
            //Kiểm tra độ liên kết

            //KiemTraDLK ktdlk = new KiemTraDLK();
            //ktdlk.NguongLK = 0.004;
            //Console.WriteLine("Doc du lieu...");
            //ktdlk.readData("1word.txt", "2word.txt");
            //Console.WriteLine("Xu ly...");
            //ktdlk.process();
            //Console.WriteLine("Ghi ket qua...");
            //ktdlk.writeData("testdllk.txt");
            //Console.WriteLine("Hoan thanh.");

            //Đếm từ

            PreProcessing.WordCounting p = new PreProcessing.WordCounting();
            int count = 0;
            string page = "";
            Console.WriteLine("Moi nhap vao duong dan noi dung:");
            string path = Console.ReadLine();
            string[] files = Directory.GetFiles(path, "*.txt",
                                         SearchOption.AllDirectories);
            int filesCount = files.Length;
            StreamWriter sw = new StreamWriter("wordcounting_train_info.txt");
            sw.WriteLine("Tổng số file: " + filesCount + "\n Số file train cho dữ liệu nhỏ: " + filesCount / 3 + "\nSố file train cho dữ liệu trung bình: " + (filesCount * 2) / 3);
            sw.Close();
            Console.WriteLine("Processing 1 word....");
            Stopwatch st = Stopwatch.StartNew();
            foreach (string link in files)
            {
                count++;
                page = File.ReadAllText(link);
                p.xuLy1(page);
                if (count == filesCount / 3)
                {
                    p.writeData("1word_small.txt");
                }
                if (count == Convert.ToInt32(filesCount * 2 / 3))
                {
                    p.writeData("1word_mid.txt");
                }
            }
            st.Stop();
            Console.WriteLine("Processed, time to elapse: " + st.Elapsed);
            Console.WriteLine("Writing data...");
            p.writeData("1word.txt");
            Console.WriteLine("Conpleted.");
            p.clear();
            Console.WriteLine("Processing 2 word....");
            count = 0;
            st = Stopwatch.StartNew();
            page = "";
            foreach (string link in files)
            {
                count++;
                page = File.ReadAllText(link);
                p.xuly2(page);
                if (count == filesCount / 3)
                {
                    p.writeData("2word_small.txt");
                }
                if (count == Convert.ToInt32(filesCount * 2 / 3))
                {
                    p.writeData("2word_mid.txt");
                }
            }
            st.Stop();
            Console.WriteLine("Processed, time to elapse: " + st.Elapsed);
            Console.WriteLine("Writing data...");
            p.writeData("2word.txt");
            Console.WriteLine("Conpleted.");
            p.clear();
            Console.WriteLine("Processing 3 word....");
            count = 0;
            st = Stopwatch.StartNew();
            page = "";
            foreach (string link in files)
            {
                count++;
                page = File.ReadAllText(link);
                p.xuly3(page);
                if (count == filesCount / 3)
                {
                    p.writeData("3word_small.txt");
                }
                if (count == Convert.ToInt32(filesCount * 2 / 3))
                {
                    p.writeData("3word_mid.txt");
                }
            }
            st.Stop();
            Console.WriteLine("Processed, time to elapse: " + st.Elapsed);
            Console.WriteLine("Writing data...");
            p.writeData("3word.txt");
            Console.WriteLine("Conpleted.");
            p.clear();
            

            //Tính xác xuất
            //StreamWriter sw = new StreamWriter(@"E:\desktop\rar\New data\Small\probability_train_info.txt");
            //Stopwatch st = new Stopwatch();
            //PreProcessing.Probability pb = new PreProcessing.Probability();
            //Console.WriteLine("reading 1word data...");
            //st = Stopwatch.StartNew();
            //pb.readDataNoUS(@"E:\desktop\rar\New data\Small\1word.txt");
            //pb.countWUS();
            //st.Stop();
            //Console.WriteLine("Completed. Elapsed time: " + st.Elapsed);
            //Console.WriteLine("Calculating...");
            //st = Stopwatch.StartNew();
            //pb.calculatingP();
            //st.Stop();
            //Console.WriteLine("Completed. Elapsed time: " + st.Elapsed);
            //Console.WriteLine("Writing...");
            //pb.writeData(@"E:\desktop\rar\New data\Small\1word_P.txt");
            //pb.writeWUS(@"E:\desktop\rar\New data\Small\1word_US_NoCount.txt");
            //sw.WriteLine("Tổng số từ có dấu gồm 1 từ: " + pb.listWord.Count + "\n Tổng số từ không dấu gồm 1 từ: " + pb.listWordUS.Count);
            //pb.clear();
            //Console.WriteLine("Completed");
            //Console.WriteLine("reading 2word data...");
            //st = Stopwatch.StartNew();
            //pb.readDataNoUS(@"E:\desktop\rar\New data\Small\2word.txt");
            //pb.countWUS();
            //st.Stop();
            //Console.WriteLine("Completed. Elapsed time: " + st.Elapsed);
            //Console.WriteLine("Calculating...");
            //st = Stopwatch.StartNew();
            //pb.calculatingP();
            //st.Stop();
            //Console.WriteLine("Completed. Elapsed time: " + st.Elapsed);
            //Console.WriteLine("Writing...");
            //pb.writeData(@"E:\desktop\rar\New data\Small\2word_P.txt");
            //pb.writeWUS(@"E:\desktop\rar\New data\Small\2word_US_NoCount.txt");
            //sw.WriteLine("Tổng số từ có dấu gồm 2 từ: " + pb.listWord.Count + "\n Tổng số từ không dấu gồm 2 từ: " + pb.listWordUS.Count);
            //pb.clear();
            //Console.WriteLine("Completed");
            //Console.WriteLine("reading 3word data...");
            //st = Stopwatch.StartNew();
            //pb.readDataNoUS(@"E:\desktop\rar\New data\Small\3word.txt");
            //pb.countWUS();
            //st.Stop();
            //Console.WriteLine("Completed. Elapsed time: " + st.Elapsed);
            //Console.WriteLine("Calculating...");
            //st = Stopwatch.StartNew();
            //pb.calculatingP();
            //st.Stop();
            //Console.WriteLine("Completed. Elapsed time: " + st.Elapsed);
            //Console.WriteLine("Writing...");
            //pb.writeData(@"E:\desktop\rar\New data\Small\3word_P.txt");
            //pb.writeWUS(@"E:\desktop\rar\New data\Small\3word_US_NoCount.txt");
            //sw.WriteLine("Tổng số từ có dấu gồm 3 từ: " + pb.listWord.Count + "\n Tổng số từ không dấu gồm 3 từ: " + pb.listWordUS.Count);
            //pb.clear();
            //Console.WriteLine("Completed");
            //sw.Close();

            //Mở giao diện

            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());
        }
    }
}
